package com.sree.tali.plugin;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernatePlugin
  implements PlugIn
{
  private Configuration config;
  private SessionFactory factory;
  private String path = "/hbms/hibernate.cfg.xml";
  private static Class clazz = HibernatePlugin.class;
  public static final String KEY_NAME = clazz.getName();
  
  public void setPath(String paramString)
  {
    this.path = paramString;
  }
  
  public void init(ActionServlet paramActionServlet, ModuleConfig paramModuleConfig)
    throws ServletException
  {
    try
    {
      URL localURL = HibernatePlugin.class.getResource(this.path);
      this.config = new Configuration().configure(this.path);
      this.factory = this.config.buildSessionFactory();
      paramActionServlet.getServletContext().setAttribute(KEY_NAME, this.factory);
    }
    catch (HibernateException localHibernateException)
    {
      localHibernateException.printStackTrace();
    }
    catch (Exception localException)
    {
      throw new ServletException();
    }
  }
  
  public void destroy()
  {
    try
    {
      this.factory.close();
    }
    catch (HibernateException localHibernateException)
    {
      localHibernateException.printStackTrace();
    }
  }
  
  public static void main() {}
}


/* Location:           D:\sreenu\talivud-new-110514\talivud-new\dist\WEB-INF\classes\
 * Qualified Name:     com.sree.tali.plugin.HibernatePlugin
 * JD-Core Version:    0.7.0.1
 */